package com.dog.modules.infra.web;

import com.alibaba.fastjson2.JSON;
import com.dog.framework.core.utils.JsonUtils;
import com.dog.framework.redis.dto.MessageDTO;
import com.dog.framework.redis.enums.RedisMqEnum;
import com.dog.framework.redis.service.RedisService;
import com.dog.framework.security.annotation.RepeatSubmit;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/test")
public class TestController {


    @Autowired
    private RedisService redisService;

    @RepeatSubmit(seconds=3)
    @GetMapping("/log")
    public String log(){
        log.info("===============hello world===========");
       // redisService.convertAndSend("TEST_TOPIC_1","hello world");
        MessageDTO messageDTO = new MessageDTO();
        messageDTO.setType(RedisMqEnum.GATEWAY_WHITE_URL_UPDATE.getCode());
        messageDTO.setContent("hello");

        redisService.convertAndSend(JSON.toJSONString(messageDTO));

       // redisService.convertAndSend(messageDTO);
       // redisService.convertAndSend("this is test message");

        return "hello world infra service";
    }

    public static void main(String[] args) {
        MessageDTO messageDTO = new MessageDTO();
        messageDTO.setType(RedisMqEnum.GATEWAY_WHITE_URL_UPDATE.getCode());
        messageDTO.setContent("hello");
        String jsonString = JsonUtils.toJsonString(messageDTO);
        System.out.println(jsonString);
        MessageDTO messageDTO1  = JsonUtils.parseObject(jsonString,MessageDTO.class);
        System.out.println(messageDTO1);
    }



}
